#include <iostream>
using namespace std;

void dfs(int n,int m,int x,int y,bool *nxm){
	if((x == -1  ||  y == -1  ||  x == m  ||  y == n)  ||  nxm[y*m+x] == false)
		return;
	nxm[y*m+x] = false;
	dfs(n,m,x-1,y,nxm);
	dfs(n,m,x,y-1,nxm);
	dfs(n,m,x+1,y,nxm);
	dfs(n,m,x,y+1,nxm);
	dfs(n,m,x-1,y-1,nxm);
	dfs(n,m,x-1,y+1,nxm);
	dfs(n,m,x+1,y+1,nxm);
	dfs(n,m,x+1,y-1,nxm);
	return;
}

int main(){
	int n,m,ans=0;
	cin>>n>>m;
	bool nxm[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			char l;
			cin>>l;
			if(l == 'W')
				nxm[i][j] = true;
			else
				nxm[i][j] = false;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(nxm[i][j]){
				dfs(n,m,j,i,&nxm[0][0]);
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}
